package com.imooc.validator;

import com.imooc.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author Zqm
 * @Title: MyConstraintValidator
 * @ProjectName SpringSecurity
 * @date 2018/12/17
 */
public class MyConstraintValidator implements ConstraintValidator<MyConstraint,Object> {

    @Autowired
    private HelloService helloService;

    /**
     * 校验器初始化
     * @param myConstraint
     */
    @Override
    public void initialize(MyConstraint myConstraint) {
        System.out.println("my validator init");
    }


    /**
     * 真正的校验逻辑
     * @param value
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
        helloService.greeting("tom");
        System.out.println(value);
        return false;
    }
}
